<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "loan_rate".
 *
 * @property integer $country_id
 * @property integer $cycle
 * @property double $loan_rate
 * @property string $create_at
 * @property string $update_at
 *
 * @property Country $country
 */
class LoanRate extends \app\models\BaseModel {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'loan_rate';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['country_id', 'cycle', 'loan_rate'], 'required'],
            [['country_id', 'cycle'], 'integer'],
            [['loan_rate'], 'number'],
            [['create_at', 'update_at'], 'safe'],
            [['country_id'], 'exist', 'skipOnError' => true, 'targetClass' => Country::className(), 'targetAttribute' => ['country_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'country_id' => 'Country ID',
            'cycle' => 'Cycle',
            'loan_rate' => 'Loan Rate',
            'create_at' => '创建时间',
            'update_at' => '更新时间',
        ];
    }

    public function fields() {
        $fields = [
            'country_id',
            'cycle',
            'loan_rate',
        ];
        $fields = array_combine($fields, $fields);

        return $fields;
    }

    public function extraFields() {
        $fields = [
            'create_at',
            'update_at',
        ];
        $fields = array_combine($fields, $fields);
        return $fields;
    }

    public function getCountry() {
        return $this->hasOne(Country::className(), ['id' => 'country_id'])->inverseOf('loanRates');
    }
}
